﻿using System;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;

namespace Fuse8.DomainFramework.Common
{
    /// <summary>
    /// 
    /// </summary>
    public static class StringExtension
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static string ToMD5Hash(this string val)
        {
            Guard.ArgumentNotEmpty(val, "inputString");

            string result;

            using (var md5 = new MD5CryptoServiceProvider())
            {
                byte[] input = Encoding.UTF8.GetBytes(val);
                result = Convert.ToBase64String(md5.ComputeHash(input));
            }

            return result;
        }
        
        internal static bool IsDbNull (this string val)
        {
			return Regex.IsMatch(val, @".*[(\s]*NULL[)\s]*");
        }
    }
}
